/**
 * 用户中间件
 */
const User = require('../model/user');

module.exports = {
    /**
     * 用户最近登录时间
     */
    lastLoginTime:(req,res,next) =>{
        User.lastLoginTime().then(results =>{
            req.lastLoginTime = results;
            next();
        }).catch(err=>{
            next(err);
        });

    },
    /**
     * 用户修改
    */
    edit:(req,res,next) =>{
        let name = req.user.username;
        let password = req.body.password;
        let repassword = req.body.repassword;
        let username = req.body.username;
        if(password != repassword){
            res.render('admin/account/index',{user:req.user,code:'两次密码不一致'});
        }
        console.log(name,username,password);
        User.edit(name,username,password).then(results =>{
            req.affectedRows = results;
            next();
        }).catch(err=>{
            next(err);
        });
    },
}
